package com.yuan.zsschool.ui.wonderful;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.yuan.base.common.adapter.TabFragmentAdapter;
import com.yuan.base.framework.BaseFrameworkFragment;
import com.yuan.zsschool.R;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * 精彩瞬间
 */
public class MainWonderfulFragment extends BaseFrameworkFragment implements Serializable {

	// --------------------------控件--------------------------
	private ViewPager vp_pager;
	private TabLayout tl_tab;
	// --------------------------变量--------------------------


	@Override
	protected int getLayoutId() {
		return R.layout.fragment_main_wonderful;
	}

	@Override
	protected void bindViews() {
		vp_pager = findViewById(R.id.vp_pager);
		tl_tab = findViewById(R.id.tl_tab);
	}

	@Override
	protected void initUI() {
		initTabs();
	}

	private void initTabs() {
		// 初始设置选中
		ArrayList<Fragment> fragmentList = new ArrayList<Fragment>();
		WonderfulFragment utd = new WonderfulFragment();
		utd.setType(1);
		fragmentList.add(utd);
		WonderfulFragment vpf = new WonderfulFragment();
		vpf.setType(2);
		fragmentList.add(vpf);
		vp_pager.setAdapter(new TabFragmentAdapter(context.getSupportFragmentManager(), fragmentList, new String[]{"视频", "图片"}));
		vp_pager.setOffscreenPageLimit(2);
		tl_tab.setupWithViewPager(vp_pager);
		TabLayout.Tab tab = tl_tab.getTabAt(0);
		if (tab != null)
			tab.select();
	}

}
